﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FrameWork.WebControls;
using FrameWork.Components;

namespace FrameWork.web.Module.IntegralMS.IntegralMS.InteralField
{
    public partial class New : System.Web.UI.Page
    {
        int CheckItemID;
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckItemID = (int)Common.sink("CheckItemID", MethodType.Get, 255, 1, DataType.Int);
            BindButton();
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        private void BindButton()
        {
            HeadMenuButtonItem bi0 = new HeadMenuButtonItem();
            bi0.ButtonIcon = "back.gif";
            bi0.ButtonName = "返回";
            bi0.ButtonPopedom = PopedomType.List;
            bi0.ButtonUrl = string.Format("GroupList.aspx?CheckItemID={0}", CheckItemID);
            HeadMenuWebControls1.ButtonList.Add(bi0);


        }

        private void OnStart()
        {
            if (CheckItemID == 0)
                C_ParentID_Txt.Text = "考核项目列表";
            else
            {
                C_ParentID_Txt.Text = BusinessFacade.stu_CheckItemDisp(CheckItemID).C_CIName;
            }

            CatListTitle.Text = string.Format("<a href='GroupList.aspx'>阶段列表</a>{0}", BusinessFacade.GetCheckItemTitle(CheckItemID));
            Button1.Attributes.Add("Onclick", "javascript:return checkForm(aspnetForm);");
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            int RecordCount = 0;
            FrameWorkPermission.CheckPermissionVoid(PopedomType.New);
            stu_CheckItemTable gt = BusinessFacade.stu_CheckItemDisp(CheckItemID);
            gt.C_CIName = (string)Common.sink(C_CIName.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            gt.C_ItemValue = (int)Common.sink(C_ItemValue.UniqueID, MethodType.Post, 0, 0, DataType.Int);
            if (gt.CheckItemID == 0)
            {
                gt.C_Level = 1;
                BusinessFacade.stu_CheckItemList(new QueryParam(), out RecordCount);
                gt.C_ShowOrder = RecordCount + 1;
            }
            else
            {

                gt.C_Level++;
                gt.C_ShowOrder = gt.C_ChildCount + 1;
                gt.C_ChildCount = 0;
                gt.C_ParentID = CheckItemID;
            }

            gt.DB_Option_Action_ = "Insert";
            BusinessFacade.stu_CheckItemInsertUpdate(gt);
            //更新子部门数
            BusinessFacade.Update_Table_Fileds("stu_CheckItem", "C_ChildCount=C_ChildCount+1", string.Format("CheckItemID={0}", CheckItemID));
            EventMessage.MessageBox(1, "操作成功", string.Format("增加考核{0})成功!", gt.C_CIName), Icon_Type.OK, Common.GetHomeBaseUrl(string.Format("GroupList.aspx?CheckItemID={0}", CheckItemID)), Common.BuildJs);
        }
    }
}